<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0 text-dark">联系我们</h1>
            </div><!-- /.col -->
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a th:href="@{admin}">首页</a></li>
                    <li class="breadcrumb-item active">网站管理</li>
                    <li class="breadcrumb-item active">联系我们</li>
                </ol>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.container-fluid -->
</div>
<!-- Main content -->
<section class="content">
    <div class="card card-body">
        <form id="contactForm">
            <input type="hidden" name="id" th:value="${contact?.id}">
            <div class="form-group row">
                <label for="companyName" class="col-sm-1 col-form-label">公司名称:</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.companyName}" name="companyName" class="form-control"
                           id="companyName"
                           placeholder="请填写公司名称" required>
                    <div class="invalid-feedback">请填写公司名称</div>
                </div>
            </div>
            <div class="form-group row">
                <label for="contacts" class="col-sm-1 col-form-label">联系人:</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.contacts}" name="contacts" class="form-control"
                           id="contacts"
                           placeholder="请填写联系人" required>
                    <div class="invalid-feedback">请填写联系人</div>
                </div>
            </div>
            <div class="form-group row">
                <label for="fixedTelephone" class="col-sm-1 col-form-label">固定电话:</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.fixedTelephone}" name="fixedTelephone"
                           class="form-control"
                           id="fixedTelephone"
                           placeholder="请填写固定电话" required>
                    <div class="invalid-feedback">请填写固定电话</div>
                </div>
            </div>
            <div class="form-group row">
                <label for="phoneNumber" class="col-sm-1 col-form-label">移动电话</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.phoneNumber}" name="phoneNumber" class="form-control"
                           id="phoneNumber" placeholder="请填写移动电话" required>
                    <div class="invalid-feedback">请填写移动电话</div>
                </div>
            </div>
            <div class="form-group row">
                <label for="mailbox" class="col-sm-1 col-form-label">邮箱:</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.mailbox}" name="mailbox" class="form-control"
                           id="mailbox"
                           placeholder="请填写邮箱" required>
                    <div class="invalid-feedback">请填写邮箱</div>
                </div>
            </div>
            <div class="form-group row">
                <label for="address" class="col-sm-1 col-form-label">公司地址:</label>
                <div class="col-sm-11">
                    <input type="text" th:value="${contact?.address}" id="address" name="address" class="form-control"
                           placeholder="请填写公司地址" required>
                    <div class="invalid-feedback">请填写公司地址</div>
                </div>
            </div>

        </form>
        <div class="btn-group mt-3">
            <button type="button" id="saveOrUpdateBtn"
                    class="btn btn-success">提交
            </button>
        </div>
    </div>
</section>
<script>

    $(function () {
        // 保存或更新
        $('#saveOrUpdateBtn').on('click', function () {
            var $f = $('#contactForm');
            var valid = $f[0].checkValidity();
            var url = "/contact/add";
            if (valid) {
                Core.mask("#saveOrUpdateBtn");
                Core.postAjax(url, $f.serialize(), function (data) {
                    Core.unmask("#saveOrUpdateBtn");
                    if (data.status === 200) {
                        Core.load("#content", "contact/add");
                    }
                    layer.msg(data.msg);
                }, function () {
                    Core.unmask("#saveOrUpdateBtn");
                })
            }
            $f.addClass("was-validated")
        })
    })

</script>
